<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>飞虾后台管理 | 登陆</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" th:href="@{/libs/bootstrap/bootstrap.min.css}">
  <!-- Font Awesome -->
  <link rel="stylesheet" th:href="@{/libs/font-awesome/font-awesome.min.css}">
  <!-- Theme style -->
  <link rel="stylesheet" th:href="@{/libs/adminlte/css/AdminLTE.min.css}">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
  <style>
    .vcode-content {
      width: 65%;
      display: inline-block;
    }
    .vcode-img {
      width: 35%;
      height: 35px;
      position: absolute;
    }
  </style>
</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <a href="#"><b>飞虾后台</b>管理系统</a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
    <p class="login-box-msg">输入账号密码以登陆后台</p>

    <form  class="login-form">
      <div class="form-group has-feedback">
        <input name="username" type="email" class="form-control" placeholder="Email">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input name="password" type="password" class="form-control" placeholder="Password">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback vcode">
        <div class="vcode-content">
          <input type="text" name="verification" class="form-control" placeholder="验证码" require="必填项" data-position="position-a">
          <span class="fa fa-key form-control-feedback"></span>
        </div>
        <img id="verificationCode" src="/verificationCode" class="pointer vcode-img">
      </div>

      <div class="row">
        <div class="col-xs-7">
          <div class="checkbox">
            <label>
              <input name="rememberMe" type="checkbox"> 记住我
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-5">
          <button id="subLogin" type="button" class="btn btn-primary btn-block btn-flat">登陆</button>
        </div>
        <!-- /.col -->
      </div>
  </form>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 3 -->
<script th:src="@{/libs/jquery/jquery.min.js}"></script>
<!-- Bootstrap 3.3.7 -->
<script th:src="@{/libs/bootstrap/bootstrap.min.js}"></script>
<!-- Layer 3.0.3 -->
<script th:src="@{/libs/layer/layer.js}"></script>
<script>
  $(function () {
    $(".vcode-img").on('click', function () {
      $(this).attr('src', '/verificationCode?' + Math.floor(Math.random() * 100));
    });

    $('#subLogin').click(function () {
      if('' == $('input[name=username]').val()){
        alert('用户名不能为空');
        return;
      } else if('' == $('input[name=password]').val()){
        alert('密码不能为空');
        return;
      } else if('' == $('input[name=verification]').val()){
        alert('验证码不能为空');
        return;
      }
      $.ajax({
        type: "POST",
        url: "/login",
        data: $('.login-form').serialize(),
        dataType: "json",
        success: function (data) {
          $(".login-box-msg").text(data.msg);
          if (data.status == 1) {
            layer.msg(data.msg, {
              offset: '30%',
              time: 800
            }, function () {
              window.location.href = "/index";
            });
          }else{
            layer.msg(data.msg, {
              icon: 2,
              offset: '30%',
              time: 2000
            });
            $("#verificationCode").click();
          }
        }
      });
    });

    $(document).keyup(function (event) {
      if (event.keyCode == 13) {
        $("#subLogin").click();
      }
    });
  });

</script>
</div>
</body>
</html>
